//
//  CCQVisitorTableViewController.swift
//  NEWweibo
//
//  Created by 神威 on 16/9/20.
//  Copyright © 2016年 ccq. All rights reserved.
//

import UIKit

class CCQVisitorTableViewController: UITableViewController , CCQVisitorViewDelegate{

    //是否登录的标示
    var isLogin:Bool = CCQUserAccountViewModel.sharedUserAccountViewModel.isLogin
    var visitorView : CCQVisitorView?
    
    //自定义View视图
    override func loadView() {
        if isLogin {
            super.loadView()
        }else{
            
            //自己提供一个视图
            visitorView = CCQVisitorView()
            
            
            //设置代理
            visitorView?.delegate = self
            
            //设置闭包
            visitorView?.loginClosure = {[weak self] in
                print("访客视图闭包调用过来的")
                self?.requestLoginOperation()
            }
            
            view = visitorView
            
            //未登录情况下
            setupNavUI()
        }
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
   

        
    }
    
    //设置导航栏按钮
    private func setupNavUI(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: #selector(loginAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(loginAction))
    }
    
    //添加点击事件
    @objc private func loginAction() {
        print("你点击了登录操作")
        
    }
    
    
    //代理方法
    func didSelectedLogin() {
        print("这是视图代理")
    }
    
    //请求登录操作
    private func requestLoginOperation(){
        let oAuthVC = CCQOAuthViewController()
        let nav = CCQNavigationViewController(rootViewController: oAuthVC)
        present(nav, animated: true, completion: nil)
    }

}
